var longestConsecutive = function(nums) {
    let maxCount = 0;
    nums = new Set(nums);
    
    for (let value of nums) {
      if (nums.has(value - 1)) continue;
      
      let curr = value, count = 1;
      while (nums.has(value + 1)) {
        nums.delete( value + 1 );
        value++;
        count++;
      }
      maxCount = Math.max(maxCount, count);
    }
    
    return maxCount;
  }